package com.ddwl.wallet.converter;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.ddwl.schema.util.DateUtil;

import java.time.Instant;

/**
 * @Author hemiaojun
 * @Date 2021/7/7 15:44
 */
public class InstantConverter implements Converter<Instant> {
    @Override
    public Class supportJavaTypeKey() {
        return Instant.class;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
    }

    @Override
    public Instant convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        return null;
    }

    @Override
    public CellData convertToExcelData(Instant value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        if (value != null) {
            return new CellData(DateUtil.formatDate(value, DateUtil.DATE_TIME_FORMAT));
        }
        return null;
    }
}
